import actionTypes from "../action-types"
import {Dispatch} from "redux";
import {serviceQryRouteMenu} from "../../request/routeMenu";


const loadingStart = () => {

    return {
        type: actionTypes.START_LOGGED_ROUTE,
        isLoading: true,
    }

};
const loadingSuccess = (token: string, menuInfo: object) => {
    return {
        type: actionTypes.SUCCESS_LOGGED_ROUTE,
        isLoading: false,
        payload: {menuInfo},
    }
};
const loadingFailed = () => {
    return {
        type: actionTypes.FAILED_LOGGED_ROUTE,
        isLoading: false,
    }
};


/*这个获取路由菜单信息*/

export const routerMenu = (data: object) => (dispatch: Dispatch) => {
    dispatch(loadingStart());
    return new Promise((resolve, reject) => {
        serviceQryRouteMenu(data).then((response: any) => {
            if (response.data.success) {
                const menuInfo = response.data.data.menuInfo;
                // debugger;
                dispatch(loadingSuccess("", menuInfo));
                resolve(response);
            } else {
                dispatch(loadingFailed());
                reject(response);

            }

        }).catch((error) => {
            dispatch(loadingFailed());
            reject(error);
        })
    })

};

